package com.sss.hloster0605;

/**
 * 线程死锁
 * 
 * @author 茶楼
 *
 */
public class DeadLockThread {
//创建两个线程知之间竞争使用的对象
	private static Object lock01 = new Object();
	private static Object lock02 = new Object();

	public static void main(String[] args) {
		new Thread(new ShareThread01()).start();
		new Thread(new ShareThread02()).start();
	}

	private static class ShareThread01 implements Runnable {
		public void run() {
			synchronized (lock01) {
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (lock02) {
					System.out.println("ShareThread01");
				}
			}
		}
	}

	private static class ShareThread02 implements Runnable {
		public void run() {
			synchronized (lock02) {
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (lock01) {
					System.out.println("ShareThread02");
				}
			}
		}
	}
}
